'''

import requests
res = requests.get("http://www.python.org")
print(res.text)
'''
'''
#可以存储混合类型

tempList = [123,'456','789']

print(tempList)

print(nameList[1])
'''
'''
nameList= ['校长','校长','小李','小鸿']
for name in nameList:
    print(name)
tempList = [123,'456','789']
nameList.append('111')
print('添加-append-添加单个元素  添加数组则变为二维数组',nameList)

nameList.extend(tempList)

print('追加-extend--直接添加数组',nameList)

nameList.insert(2,3)
print('插入-insert',nameList)

#del nameList[1]
#nameList.pop() 删除最后一个
nameList.remove('校长') #删除制定元素 只删除第一次找到的元素
print('删除-del 删除对应位置元素',nameList)

nameList[1]='修改'
print('修改-修改对应下标数据',nameList)

findName = input('请输入名字')
if findName in nameList:
    print('找到了')
else:
    print('没找到')
'''

'''
a = ['a','b','c','d','e','f','c','c']
print('查找对应范围是否存在并返下标 左闭右开',a.index('c',1,4))

a.count('c')
print('统计-- 元素出现次数',a.count('c'))

a = [1,3,2,4,5,7]
print(a)
#翻转
a.reverse()
print(a)
a.sort()
print('升序',a)
a.sort(reverse=True)
print('降序',a)
'''
# schoolName=[[],[],[]]
# schoolName[0]=['北京','天津']
# print(schoolName[0])
# schoolName[1]=['山东','海洋大学','湖北']
# print(schoolName[1][2])
#
# offices = [[],[],[]]
# names=['a','b','c','d','e','f']
# import random
# random.shuffle(names)
# for name in names:
#     index=random.randint(0,2)
#     offices[index].append(name)
# print(offices)
# i = 1
# for office in offices:
#     print('办公室%d人数：%d人数'%(i,len(office)))
#     i += 1
#     for name in office:
#         print(name,end='\t')
#     print(' ',end='\n')
#     print('--'*30)

#练习
products = [['iphone',6800],['小米',4000],['华为',4000]]
cart = []
while True:
    # 显示商品列表及对应的下标和价格
    print("商品列表：")
    for i in range(len(products)):
        product_name = products[i][0]
        price = products[i][1]
        print(f"{i}. {product_name} - ￥{price}")
    # 提示用户输入要添加的商品下标或输入 q 进行结算
    choice = input("请输入要添加的商品下标（输入 q 结算）：")
    if choice == 'q':
        break
    try:
        # 将用户输入的下标转换为整数
        index = int(choice)
        # 检查输入的下标是否在有效范围内
        if 0 <= index < len(products):
            # 将有效的商品下标添加到购物车中
            cart.append(index)
            product_name = products[index][0]
            print(f"{product_name} 已添加到购物车。")
        else:
            print("输入的下标无效，请重新输入。")
    except ValueError:
        print("输入无效，请输入有效的下标或 q 进行结算。")
# 结算部分
total = 0
print("购物车内容：")
for index in cart:
    # 根据购物车中的下标获取商品名称和价格
    product_name = products[index][0]
    price = products[index][1]
    print(f"{product_name} - ￥{price}")
    # 累加商品价格到总价
    total += price
print(f"总价：￥{total}")